//
//  WLCloudDetailVController.m
//  WanLian
//
//  Created by muzhuang on 2018/11/3.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLCloudDetailVController.h"
#import "WLCloudDetailCell.h"
#import "NSString+Ext.h"

@interface WLCloudDetailVController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableDetail;
//@property (nonatomic, strong) WLCloudFileModel *fileModel;

@end

@implementation WLCloudDetailVController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"详细信息";
    
    _tableDetail = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableDetail.delegate = self;
    _tableDetail.dataSource = self;
    _tableDetail.rowHeight  = WLScaleX(58);
    _tableDetail.scrollEnabled = NO;
    if (@available(iOS 11.0, *)) {
        _tableDetail.estimatedSectionHeaderHeight = 0;
        _tableDetail.estimatedSectionFooterHeight = 0;
    }
    _tableDetail.tableFooterView = [UIView new];
    [self.view addSubview:_tableDetail];
    WLWkSelf
    [_tableDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
    [_tableDetail reloadData];
//    [self queryFileDetail];
}

- (void)queryFileDetail
{
//    WLWkSelf
//    NSDictionary *params = @{@"id":@(_fileID)};
//    [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"storage/item/query" withParamsDic:params success:^(NSDictionary *successDict) {
//        weakSelf.fileModel = [WLCloudFileModel mj_objectWithKeyValues:successDict[@"object"]];
//        [weakSelf.tableDetail reloadData];
//    } failure:^(NSString *errorMsg, NSInteger errorTag) {
//        [weakSelf showHUDMessage:errorMsg];
//    } error:^(NSError *error) {
//
//    } inView:self.view];
}

#pragma mark - UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return WLScaleX(20);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = indexPath.row;
    static NSString *detailCell = @"detailCell";
    WLCloudDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:detailCell];
    if (!cell) {
        cell = [[WLCloudDetailCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:detailCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.labDetail.textAlignment = NSTextAlignmentRight;
    if (row==0) {
        cell.labTitle.text = @"文件名称";
        cell.labDetail.text = _fileModel.fileName;;
    }
    else if (row==1)
    {
        cell.labTitle.text = @"修改时间";
        NSString *date = [NSString timestampSwitchTime:_fileModel.uploadTime andFormatter:@"yyyy/MM/dd HH:mm"];
        cell.labDetail.text = date;
    }
    else if (row==2)
    {
        cell.labTitle.text = @"文件大小";
        cell.labDetail.text = [NSString formateSizeWithKBytes:[_fileModel.fileSize longLongValue]];
//        if (_photoModel != nil) {
//            UIImage *imgCached = [[SDImageCache sharedImageCache] imageFromCacheForKey:_photoModel.filepath];
//            NSData *data = UIImagePNGRepresentation(imgCached);
//            if (!data) {
//                data = UIImageJPEGRepresentation(imgCached, 0.5);
//            }
//            double dataLength = data.length/(1024.0*1024.0);
//            cell.labDetail.text = [NSString stringWithFormat:@"%.2fM",dataLength];
//        }
//        else
//        {
//            cell.labDetail.text = _fileModel.fileSize;
//        }
    }
    else if (row==3)
    {
//        cell.labDetail.textAlignment = NSTextAlignmentLeft;
        cell.labTitle.text = @"文件路径";
        cell.labDetail.text = _fileModel.filePath;;
    }
    
    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
